<template>
  <div>
    <!-- table -->
    <!-- 技术报告查询 - 技术报告录入编辑 -->
    <BreakSpace label="基本信息" :containerStyle="{ marginBottom: '10px' }"/>
    <FormPanel ref="formPanel1" :list="formList" :cols="3" :formType="'add'" labelWidth="130" :isSubmitBtn="false" @formChange="formChangeHandle"/>
    <div style="margin-bottom: 1rem;"></div>
    <BreakSpace label="故障信息" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :dataSource="dataList"
      :isPagination=false
      height="auto"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :isSelectColumn=false
    ></FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <FormPanel ref="formPanel5" :list="formList5" :cols="3" :formType="'add'" labelWidth="140" :isSubmitBtn="false"/>
    <div style="margin-bottom: 2rem;"></div>
    <BreakSpace label="经销商-车厂沟通历史" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table1"
      :columns="columns2"
      :params="fetchParams"
      :dataSource="dataList2"
      :isPagination=false
      height="auto"
      :onColumnsChange="columns => (this.columns2 = columns2)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :isSelectColumn=false
    ></FilterTable>
    <div style="margin-bottom: 2rem;"></div>
    <BreakSpace label="质量部回复历史" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table2"
      :columns="columns3"
      :params="fetchParams"
      :dataSource="dataList3"
      height="auto"
      :isPagination=false
      :onColumnsChange="columns => (this.columns3 = columns3)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :isSelectColumn=false
    ></FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <BreakSpace label="现场人员处理过程" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table3"
      :columns="columns4"
      :params="fetchParams"
      :dataSource="dataList4"
      :isPagination=false
      height="auto"
      :onColumnsChange="columns => (this.columns4 = columns4)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :isSelectColumn=false
    ></FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <FormPanel ref="formPanel2" :list="formList2" :cols="3" :formType="'add'" labelWidth="140" :isSubmitBtn="false" @formChange="formChangeHandle2"/>
    <div style="margin-bottom: 1rem;"></div>
    <BreakSpace label="现场人员处理结果维护" :containerStyle="{ marginBottom: '10px' }"/>
    <FormPanel ref="formPanel3" :list="formList3" :cols="3" :formType="'add'" labelWidth="140" :isSubmitBtn="false" @formChange="formChangeHandle3"/>
    <div style="margin-bottom: 1rem;"></div>
    <BreakSpace label="经销商关单信息维护" :containerStyle="{ marginBottom: '10px' }"/>
    <FormPanel ref="formPanel4" :list="formList4" :cols="3" :formType="'add'" labelWidth="140" :isSubmitBtn="false" @formChange="formChangeHandle4"/>
    <div style="margin-bottom: 1rem;"></div>
    <div style="padding-top: 3rem;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
    <BaseDialog :visible.sync="RepairWorkOrderVisible" :title="'维修工单选择'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <RepairWorkOrderVehicle @close="repairWorkOrderClose" @save="repairWorkOrderSave"></RepairWorkOrderVehicle>
    </BaseDialog>
    <BaseDialog :title="'查看附件'" :visible.sync="upVisible" destroyOnClose>
      <uploadFile :rowData="oemId" @close="upVisible = false"></uploadFile>
    </BaseDialog>
  </div>
</template>
<script>
import RepairWorkOrderVehicle from './RepairWorkOrderVehicle.vue';
import uploadFile from '@/pages/claimDemage/TechnicalSupport/uploadFile.vue';
//字典
import { getPartType } from '@/api/dictionary/index';
//后台请求
import { selectById, editSave ,checkFirst }  from '@/api/technicalReportManagement/technicalSupportManagement_DLR/technicalReportQuery/index';
import { queryBalanceOrderForClaim }  from '@/api/dictionary/index';

export default {
  props: ['rowData'],

  // mixins: [dictionary],
  components: {
    RepairWorkOrderVehicle,
    uploadFile
  },
  data() {
    return {
      dataList: [],
      dataList2: [],
      dataList3: [],
      dataList4: [],
      RepairWorkOrderVisible: false,
      upVisible: false,
      infoId: null,
      columns: this.creatHeader(),
      columns2: this.creatHeader2(),
      columns3: this.creatHeader3(),
      columns4: this.creatHeader4(),
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      formList: this.createFormList(),
      formList2: this.createFormList2(),
      formList3: this.createFormList3(),
      formList4: this.createFormList4(),
      formList5: this.createFormList5(),
      saveData: null,
      saveData2: null,
      saveData3: null,
      saveData4: null,
      oemId: null
    };
  },
  created() {
    this.chuqi();
    this.init();
  },
  methods: {
    async init() {
      const newVar = await selectById({id: this.rowData.techId});
      this.editData = newVar.data;
      this.modelId = newVar.data.modelId;
      this.modelCode = newVar.data.modelCode;
      console.log("=== 通过ID查询结果返回 ==== ",this.editData," ======");
      this.formList.forEach(x => {
        console.log(newVar);
        x.initialValue = newVar.data[x.fieldName];
      });
      this.formList2.forEach(x => {
        x.initialValue = newVar.data[x.fieldName];
        if (x.fieldName == 'dealFileList') {
          x.initialValue = newVar.data.dealFileList.map((f) => ({ name: f.title, url: f.fileUrl }));
        }
      });
      this.formList3.forEach(x => {
        x.initialValue = newVar.data[x.fieldName];
        if (x.fieldName == 'resultFileList') {
          x.initialValue = newVar.data.resultFileList.map((f) => ({ name: f.title, url: f.fileUrl }));
        }
      });
      this.formList4.forEach(x => {
        x.initialValue = newVar.data[x.fieldName];
      });
      this.formList5.forEach(x => {
        x.initialValue = newVar.data[x.fieldName];
        if (x.fieldName == 'applyFileList') {
          x.initialValue = newVar.data.applyFileList.map((f) => ({ name: f.title, url: f.fileUrl }));
        }
      });
      this.$refs.table.$refs.pageTable.EXECUTE_INSERT(newVar.data.faultList);
      this.$refs.table1.$refs.pageTable.EXECUTE_INSERT(newVar.data.oemList);
      this.$refs.table2.$refs.pageTable.EXECUTE_INSERT(newVar.data.qualityList);
      this.$refs.table3.$refs.pageTable.EXECUTE_INSERT(newVar.data.siteList);

      if (this.editData.roNo != null) {
        let newVar1 = await queryBalanceOrderForClaim({RO_NO: this.editData.roNo});
        console.log("123213");
        console.log(newVar1.data.rows[0]);
        this.formList4.find(x => x.fieldName == 'RO_CREATE_DATE').initialValue = newVar1.data.rows[0].RO_CREATE_DATE;
        this.formList4.find(x => x.fieldName == 'SQUARE_DATE').initialValue = newVar1.data.rows[0].SQUARE_DATE;
        this.formList4.find(x => x.fieldName == 'REPAIR_TYPE_NAME').initialValue = newVar1.data.rows[0].REPAIR_TYPE_NAME;
        this.formList4.find(x => x.fieldName == 'PRODUCT_DATE').initialValue = newVar1.data.rows[0].PRODUCT_DATE;
        this.formList4.find(x => x.fieldName == 'SALES_DATE').initialValue = newVar1.data.rows[0].SALES_DATE;
        this.formList4.find(x => x.fieldName == 'modelName').initialValue = newVar1.data.rows[0].MODEL_NAME;
        this.formList4.find(x => x.fieldName == 'IN_MILEAGE').initialValue = newVar1.data.rows[0].IN_MILEAGE;
        this.formList4.find(x => x.fieldName == 'LICENSE').initialValue = newVar1.data.rows[0].LICENSE;

      }

      // this.$refs.table2.$refs.pageTable.EXECUTE_INSERT(newVar.data.logList);
    },
    async chuqi() {
      //是否首次咨询
      const res1 = await getPartType({type: 5500});
      if (res1.resultCode == 200) {
        this.formList.find(x => x.fieldName == 'ifFirst').itemList = res1.data.map(y => ({
          text: y.codeCnDesc,
          value: y.codeId
        }));
        this.formList3.find(x => x.fieldName == 'ifRepeat').itemList = res1.data.map(y => ({
          text: y.codeCnDesc,
          value: y.codeId
        }));
        this.formList3.find(x => x.fieldName == 'ifDeal').itemList = res1.data.map(y => ({
          text: y.codeCnDesc,
          value: y.codeId
        }));
      }
      //状态
      const res2 = await getPartType({type: 5552});
      if (res2.resultCode == 200) {
        this.formList.find(x => x.fieldName == 'techStatus').itemList = res2.data.map(y => ({
          text: y.codeCnDesc,
          value: y.codeId
        }));
      }
      //受理类型
      const res3 = await getPartType({type: 5553});
      if (res3.resultCode == 200) {
        this.formList.find(x => x.fieldName == 'acceptType').itemList = res3.data.map(y => ({
          text: y.codeCnDesc,
          value: y.codeId
        }));
      }
      //是否已解决
      const res4 = await getPartType({type: 5557});
      if (res3.resultCode == 200) {
        this.formList4.find(x => x.fieldName == 'dlrIfDeal').itemList = res4.data.map(y => ({
          text: y.codeCnDesc,
          value: y.codeId
        }));
      }
    },
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    formChangeHandle2(val) {
      console.log(val);
      this.saveData2 = val;
    },
    formChangeHandle3(val) {
      console.log(val);
      this.saveData3 = val;
    },
    formChangeHandle4(val) {
      console.log(val);
      this.saveData4 = val;
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //取消操作
    closeDialog() {
      this.$emit('close', {visible: false, data: this.selectedRows, type: 'close'});
    },
    repairWorkOrderTurnOn() {
      this.RepairWorkOrderVisible = true;
    },
    repairWorkOrderClose(){
      this.RepairWorkOrderVisible = false;
    },
    repairWorkOrderSave(obj) {
      this.formList4.find(x => x.fieldName == 'roNo').initialValue = obj[0].address;
      this.RepairWorkOrderVisible = false;
    },
    fileOemTurnOn(val) {
      this.oemId = val.oemId;
      this.upVisible = true;
    },
    fileQaTurnOn(val) {
      this.oemId = val.qaId;
      this.upVisible = true;
    },
    //基本信息
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '技术报告单号',
          fieldName: 'techNo',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'techStatus',
          itemList: [],
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'SELECT',
          label: '是否首次咨询',
          fieldName: 'ifFirst',
          itemList: [],
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '所属区域',
          fieldName: 'belongArea',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '经销商联系人',
          fieldName: 'dcPerson',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '经销商联系人电话',
          fieldName: 'dcTel',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'DATE',
          label: '提交时间',
          fieldName: 'firstDate',
          dateType: 'datetime',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          unitRender: p => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.vinTurnOn()}/>
              </div>
            );
          },
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelName',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '行驶里程',
          fieldName: 'driveMile',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'DATE',
          label: '生产日期',
          fieldName: 'prodDate',
          valueFormat: 'yyyy-MM-dd',
          dateType: 'datetime',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'DATE',
          label: '销售日期',
          fieldName: 'saleDate',
          valueFormat: 'yyyy-MM-dd',
          dateType: 'datetime',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'licenseNo',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'SELECT',
          label: '故障类型',
          fieldName: 'acceptType',
          itemList: [],
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'TEXT_AREA',
          label: '说明',
          fieldName: 'techInfos',
          selfCols: 3,
          rows: 2,
          readonly: true,// 只读
          disabled: true // 置会
        }
      ];
    },
    //故障信息
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {title: '一级', dataIndex: 'sysName1', sorter: true},
        {title: '二级', dataIndex: 'sysName2', sorter: true},
        {title: '三级', dataIndex: 'sysName3', sorter: true},
        {title: '故障名称', dataIndex: 'sysName4', sorter: true},
        {title: '故障现象代码', dataIndex: 'faultCode', sorter: true},
        {title: '故障现象名称', dataIndex: 'faultName', sorter: true},
        {title: '故障码', dataIndex: 'errorCode', sorter: true},
        {title: '故障码触发条件', dataIndex: 'faultCondition', sorter: true},
        {title: '本车是否首发', dataIndex: 'ifFirstStr', sorter: true},
        {title: '备注', dataIndex: 'remarks', sorter: true}
      ];
    },
    //故障信息附件
    createFormList5() {
      return [
        {
          type: 'UPLOAD_FILE',
          label: '查看文件',
          fieldName: 'applyFileList',
          placeholder: '上传文件...',
          initialValue: [],
          readonly: true,// 只读
          disabled: true, // 置会
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 2,
            // tipText: '只能上传pdf格式'
          }
        }
      ];
    },
    //经销商-车厂沟通历史
    creatHeader2() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 80,
          render: (props, h) => {
            return (
              <div>
                <multiuse-button  size="mini" type="text" onClick={() => this.fileOemTurnOn(props.row)}>
                  查看附件
                </multiuse-button>
              </div>
            );
          }
        },
        { title: '经销商人员', dataIndex: 'dealerUser', sorter: true },
        { title: '经销商提交时间', dataIndex: 'dApplyDate', sorter: true},
        { title: '故障现象描述', dataIndex: 'faultInfo', sorter: true },
        { title: '检修经过', dataIndex: 'cmsClaimProcess', sorter: true },
        { title: '维修结果', dataIndex: 'cmsClaimResult', sorter: true },
        { title: '车厂处理人', dataIndex: 'dealBy', sorter: true },
        { title: '车厂处理时间', dataIndex: 'dealDate', sorter: true},
        { title: '维修方案', dataIndex: 'cmsClaimCase', sorter: true },
        // { title: '附件', dataIndex: 'date', sorter: true },
      ];
    },
    //质量部回复历史
    creatHeader3() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 80,
          render: (props, h) => {
            return (
              <div>
                <multiuse-button  size="mini" type="text" onClick={() => this.fileQaTurnOn(props.row)}>
                  查看附件
                </multiuse-button>
              </div>
            );
          }
        },
        {title: '联系人', dataIndex: 'connectBy', sorter: true},
        {title: '联系电话', dataIndex: 'connectPhone', sorter: true},
        {title: '回复状态', dataIndex: 'connectStatus', sorter: true},
        {title: '反馈时间', dataIndex: 'connectDate', sorter: true, dateFormat: 'yyyy-MM-dd'},
        {title: '处理意见', dataIndex: 'cmsClaimCase', sorter: true},
        {title: '附件', dataIndex: 'date', sorter: true}
      ];
    },
    //现场人员处理过程
    creatHeader4() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '日期', dataIndex: 'siteDate', sorter: true , dateFormat: 'yyyy-MM-dd'},
        { title: '进度', dataIndex: 'speedPro', sorter: true },
        { title: '维修经过', dataIndex: 'cmsClaimProcess', sorter: true },
      ];
    },
    //附件
    createFormList2() {
      return [
        {
          type: 'UPLOAD_FILE',
          label: '查看文件',
          fieldName: 'dealFileList',
          placeholder: '上传文件...',
          initialValue: [],
          readonly: true,// 只读
          disabled: true, // 置会
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 2,
            // tipText: '只能上传pdf格式'
          }
        }
      ];
    },
    //现场人员处理结果维护
    createFormList3() {
      return [
        {
          type: 'INPUT',
          label: '现场处理人',
          fieldName: 'siteDealerStr',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'DATE',
          valueFormat: 'yyyy-MM-dd',
          dateType: 'datetime',
          label: '分配时间',
          fieldName: 'disDate',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'DATE',
          valueFormat: 'yyyy-MM-dd',
          dateType: 'datetime',
          label: '预计到达时间',
          fieldName: 'estDate',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'DATE',
          valueFormat: 'yyyy-MM-dd',
          dateType: 'datetime',
          label: '实际到达时间',
          fieldName: 'actDate',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'SELECT',
          label: '故障现象是否复现',
          fieldName: 'ifRepeat',
          itemList: [],
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'SELECT',
          label: '是否已解决',
          fieldName: 'ifDeal',
          itemList: [],
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'UPLOAD_FILE',
          label: '查看文件',
          fieldName: 'resultFileList',
          placeholder: '上传文件...',
          initialValue: [],
          readonly: true,// 只读
          disabled: true, // 置会
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 10,
            // tipText: '只能上传pdf格式'
          }
        }
      ];
    },
    //经销商关单信息维护
    createFormList4() {
      return [
        {
          type: 'INPUT',
          label: '维修工单',
          fieldName: 'roNo',
          unitRender: p => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.repairWorkOrderTurnOn()}/>
              </div>
            );
          },
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '维修开始时间',
          fieldName: 'RO_CREATE_DATE',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '维修结束时间',
          fieldName: 'SQUARE_DATE',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '工单状态',
          fieldName: 'REPAIR_TYPE_NAME',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '生产时间',
          fieldName: 'PRODUCT_DATE',
          valueFormat: 'yyyy-MM-dd',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '销售时间',
          fieldName: 'SALES_DATE',
          valueFormat: 'yyyy-MM-dd',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelName',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '行驶里程',
          fieldName: 'IN_MILEAGE',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'LICENSE',
          readonly: true,// 只读
          disabled: true // 置会
        },
        // {
        //   type: 'INPUT',
        //   label: '主损件代码',
        //   fieldName: 'data8',
        //   readonly: true,// 只读
        //   disabled: true // 置会
        // },
        // {
        //   type: 'INPUT',
        //   label: '主损件名称',
        //   fieldName: 'data9',
        //   readonly: true,// 只读
        //   disabled: true // 置会
        // },
        {
          type: 'SELECT',
          label: '处理结果',
          fieldName: 'dlrIfDeal',
          itemList: [],
          readonly: true,// 只读
          disabled: true // 置会
        }
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
